﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t103Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t103_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t103Mgr mgr = new t103Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t103(e.Parameters[t103_Filter.ParamPrefix]));
            IList<t103> list = mgr.FindAllByPage_t103(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t103_Filter.ParamPrefix]);
            t103_MainStore.DataSource = list;
            t103_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t103Mgr mgr = new t103Mgr();
            RowSelectionModel sm = t103_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t103 _t103 = new t103();
                _t103.t103_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t103(_t103))
                {
                    log.Debug("t103中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t103_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t103Mgr mgr = new t103Mgr();
            t103 _t103 = new t103();
            if (Hid.Text.Length > 0)
                _t103 = mgr.FindById_t103(int.Parse(Hid.Text));
            
			_t103.t103_01 = Txtt103_01.Text.Trim();
			_t103.t103_02 = Txtt103_02.Text.Trim();
			_t103.t103_03 = Txtt103_03.Text.Trim();
			_t103.t103_04 = Txtt103_04.Text.Trim();
			_t103.t103_05 = Txtt103_05.Text.Trim();
			_t103.t103_06 = Txtt103_06.Text.Trim();
			_t103.t103_07 = Txtt103_07.Text.Trim();
			_t103.t103_08 = Txtt103_08.Text.Trim();
			_t103.t103_09 = Txtt103_09.Text.Trim();
			_t103.t103_10 = Txtt103_10.Text.Trim();
			_t103.t103_11 = Txtt103_11.Text.Trim();
			_t103.t103_73 = Txtt103_73.Text.Trim();
			_t103.t103_74 = Txtt103_74.Text.Trim();
			_t103.t103_12 = Txtt103_12.Text.Trim();
			_t103.t103_13 = Txtt103_13.Text.Trim();
			_t103.t103_14 = Txtt103_14.Text.Trim();
			_t103.t103_70 = Txtt103_70.Text.Trim();
			_t103.t103_15 = Txtt103_15.Text.Trim();
			_t103.t103_16 = Txtt103_16.Text.Trim();
			_t103.t103_17 = Txtt103_17.Text.Trim();
			_t103.t103_18 = Txtt103_18.Text.Trim();
			_t103.t103_71 = Txtt103_71.Text.Trim();
			_t103.t103_72 = Txtt103_72.Text.Trim();
			_t103.t103_19 = Txtt103_19.Text.Trim();
			_t103.t103_20 = Txtt103_20.Text.Trim();
			_t103.t103_21 = Txtt103_21.Text.Trim();
			_t103.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t103(_t103);
            else
                isok = mgr.Add_t103(_t103);
            if (isok)
            {
                t103_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t103中执行了保存（插入或修改），并成功");
                t103_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}